﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace NxChatQQ.Views.Settings
{
    /// <summary>
    /// NormalSettingView.xaml 的交互逻辑
    /// </summary>
    public partial class NormalSettingView : UserControl
    {
        public NormalSettingView()
        {
            InitializeComponent();
        }

        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            e.Handled = true;
            var len = 100 / e.NewValue;
            var num = (int)Math.Round(len);
            fontSlider.Value = num * 25;
        }

        private bool isDown = false;

        private void Grid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            isDown = true;
            Grid_PreviewMouseMove(sender, e);
        }

        private void Grid_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (isDown)
            {
                var point = e.GetPosition(fontSlider);
                var pre = point.X / fontSlider.ActualWidth * 100;

                var num = (int)Math.Round(pre / 25);

                UpdateFontLevel(num);
            }
        }


        private void Grid_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            isDown = false;
        }


        private void UpdateFontLevel(int num)
        {
            fontSlider.Value = num * 25;

        }
    }
}
